package com.example.seckill.error;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.error.ErrorAttributeOptions;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.WebRequest;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@Component
public class MyErrorAttributes extends DefaultErrorAttributes {
    @Override
    public Map<String, Object> getErrorAttributes(WebRequest webRequest, ErrorAttributeOptions options) {
        Map<String, Object> errorAttributes = super.getErrorAttributes(webRequest, options);
//        log.error(errorAttributes.toString());
        Map<String, Object> map = new HashMap<>();
        map.put("status", "fail");
        map.put("data",  CommonErrorEnum.NOT_FOUND_404.setErrMsg("url路径错误,请返回首页"));
        return map;
    }
}
